package com.qingxin.ui.bean;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.map.annotate.JsonSerialize;


/**
 * 树节点数据(ztree适用)
 */
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class TreeNode extends BaseNode {
	private String pid;			//上级数据ID
	private boolean isParent;	//是否显示为父节点
	private boolean notclick;	//是否可点击
	private boolean dynamic;	//是否包含动态标签
	private String iconSkin;	//图标CSS
	private List<TreeNode> children;
	
	public TreeNode() {
	}
	public TreeNode(String id, String name, boolean isParent) {
		this.id = id;
		this.name = name;
		this.isParent = isParent;
	}
	
	public TreeNode(String id, String name, String type, String field, boolean isParent) {
		this.id = id;
		this.name = name;
		this.type = type;
		this.field = field;
		this.isParent = isParent;
	}
	
	
	
	public String getPid() {
		return pid;
	}
	public void setPid(String pid) {
		this.pid = pid;
	}
	public boolean isIsParent() {
		return isParent;
	}
	public void setIsParent(boolean isParent) {
		this.isParent = isParent;
	}
	public boolean isNotclick() {
		return notclick;
	}
	public void setNotclick(boolean notclick) {
		this.notclick = notclick;
	}
	public boolean isDynamic() {
		return dynamic;
	}
	public void setDynamic(boolean dynamic) {
		this.dynamic = dynamic;
	}
	public String getIconSkin() {
		return iconSkin;
	}
	public void setIconSkin(String iconSkin) {
		this.iconSkin = iconSkin;
	}

	public List<TreeNode> getChildren() {
		return children;
	}
	public void setChildren(List<TreeNode> children) {
		this.children = children;
	}
	public void addChild(TreeNode node){
		if(children==null){
			children = new ArrayList<TreeNode>();
		}
		children.add(node);
		if(node.getPid()==null){
			node.setPid(this.id);
		}
	}
	
	public TreeNode copy() {
		TreeNode target = new TreeNode();
		super.copyTo(target);
		target.setPid(pid);
		target.setIsParent(isParent);
		target.setNotclick(notclick);
		target.setDynamic(dynamic);
		target.setIconSkin(iconSkin);
		
		if(children!=null){
			List<TreeNode> childrenNodeList = new ArrayList<TreeNode>();
			for(TreeNode node : children){
				TreeNode cnode = node.copy();
				childrenNodeList.add(cnode);
			}
			target.setChildren(childrenNodeList);
		}
		
		return target;
	}
	
}
